package com.prawn.trace.record.controller;
import java.util.Date;
import java.util.List;
import java.util.Map;

import com.prawn.trace.record.pojo.InvestType;
import com.prawn.trace.record.service.InvestTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;


import entity.PageResult;
import entity.Result;
import entity.StatusCode;
/**
 * 控制器层
 * @author Administrator
 *
 */
@RestController
@CrossOrigin
@RequestMapping("/investType")
public class InvestTypeController {

	@Autowired
	private InvestTypeService investTypeService;
	
	
	/**
	 * 查询全部数据
	 * @return
	 */
	@RequestMapping(method= RequestMethod.GET)
	public Result findAll(){
		return new Result(true,StatusCode.OK,"查询成功",investTypeService.findAll());
	}
	
	/**
	 * 根据ID查询
	 * @param id ID
	 * @return
	 */
	@RequestMapping(value="/{id}",method= RequestMethod.GET)
	public Result findById(@PathVariable String id){
		return new Result(true,StatusCode.OK,"查询成功",investTypeService.findById(id));
	}
//
//	/**
//	 * 查询投入品类型树信息
//	 * @return Result
//	 */
//	@RequestMapping("/tree")
//	@ResponseBody
//	public Result getTree() {
//		return investTypeService.getInvestTypeTree(null);
//	}
	/**
	 * 查询投入品类型树信息
	 * @return Result
	 */
	@RequestMapping("/tree")
	@ResponseBody
	public Result getTree(String createBy) {
		return investTypeService.getInvestTypeTree(createBy);
	}


	/**
	 * 增加
	 * @param investType
	 */
	@RequestMapping(method=RequestMethod.POST)
	public Result add( InvestType investType  ){
		investType.setCreateDate(new Date());
		investType.setUpdateDate(new Date());
		investTypeService.add(investType);
		return new Result(true,StatusCode.OK,"增加成功");
	}
	
	/**
	 * 修改
	 * @param investType
	 */
	@RequestMapping(value="/{id}",method= RequestMethod.PUT)
	public Result update( InvestType investType, @PathVariable String id ){
		investType.setId(id);
		investType.setUpdateDate(new Date());
		investTypeService.update(investType);		
		return new Result(true,StatusCode.OK,"修改成功");
	}
	
	/**
	 * 删除
	 * @param id
	 */
	@RequestMapping(value="/{id}",method= RequestMethod.DELETE)
	public Result delete(@PathVariable String id ){
		investTypeService.deleteById(id);
		return new Result(true,StatusCode.OK,"删除成功");
	}
	
}
